

	public class Olimpiadi {

		public static int[] migliori(int[][]m){
			
			int[] temp=new int[m[0].length];
			int somma=0;
			for(int i=0; i<m.length; i++){
				for(int j=0; j<m[0].length; j++){
				
					somma=sommaColonna(m,j);
					temp[j]=somma;//vett con le somme delle singole colonne
				}
			}
			System.out.print("temp: ");
			for(int h=0; h<temp.length; h++){
				System.out.print(temp[h]+" ");
				
			}
			System.out.println();
			/*int col=0; 
			int max=0;		
			for(col=0; col<temp.length; col++){
				max=temp[0];
				if(max<temp[col])
					max=temp[col];
			}
			System.out.println("colonna max= "+col+" deve essere 2 non 4! che poi 4 nemmeno esiste!!!");*/
			
			int max=indicemax(temp);
			System.out.print("indice max: "+max);
			System.out.println();
			int[] ris=new int[m.length];
			for(int i=0; i<m.length; i++){
				for(int j=0; j<m[0].length; j++){
					ris[i]=m[i][2];
				}
				}
					
			return ris;
		}//migliori
		
		static int sommaColonna(int[][] mat, int ic){
		int i, sommac=0;
		for (i=0; i < mat.length; i++)
		sommac = sommac + mat[i][ic];
		return sommac;
		}//sommaColonna
		static int indicemax(int[]v){
			int i=0, max=0;
			for( i=1; i<v.length-1; i++){
				 max=v[0];
				if(max<v[i])
					max=v[i];
			}
			System.out.println(max);
			return i;
		}//indicemax
		
		public static int[] preferite(int[][]m, int s){
			if(s<0 | s>m.length){
				System.out.println("riga non valida");
				System.exit(-1);
			}
			int[]temp=new int[m[0].length];
			for(int i=0; i<m.length; i++){
				for(int j=0; j<m[0].length; j++){
					temp[j]=m[s][j];
					}
				}
			for(int i=0; i<temp.length; i++){
				System.out.print(temp[i]+" ");
			}
			System.out.println();
			int max=0;
			int in=0;
			max=temp[0];
			System.out.println("max orig: "+max);
			for( in=1; in<temp.length; in++){
				
				
				if(max<temp[in]){
					max=temp[in];
					System.out.println("indice: "+in);
				}
			}
			System.out.println();
			System.out.println("max: "+max);
		
			int[]ris=new int[temp.length];
			for(int i=0; i<ris.length; i++){
				ris[i]=temp[in];
			}
			return ris;
		}//preferite
		
		public static double[] maxmin(double[]a, double[]b){
			int cont=0;
		int i=0;
		int j=i+1;
		int k=i-1;
		for( i=1; i<a.length-1; i++){
			
			if(a[i]<a[j] && a[i]<a[k]) cont++;
		}
		double[]ris= new double[cont+2];
		if(i==0){
		for(i=0; i<a.length; i++){
			if(a[i]<a[j]) ris[cont]=a[i];
			ris[cont]=a[j];
		}
		}
		if(i==a.length){
			for(i=0; i<a.length; i++){
				if(a[i]<a[k]) ris[cont]=a[i];
				ris[cont]=a[k];
			}
		}
		
		
		return ris;

		
		
		
		
		}
		public static void main(String[] args) {
			
			double[]a={1.4,2.2,5.5,6.1,7.3,8.0,9.1};
			double[]b={1.5,3.6,4.4,3.9,1.0,2.2,0.7};
			double[]risa=maxmin(a,b);
			for(int i=0; i<risa.length; i++){
				System.out.print(risa[i]+" ");
			}
			System.out.println();
			
			int[][]m={{9,4,8,3},{6,10,7,5},{4,6,8,9},{6,5,9,2},{4,7,10,9}};
			int[]mig=migliori(m);
			System.out.print("colonna con voti migliori: ");
			for(int i=0; i<mig.length; i++){
				System.out.print(mig[i]+" ");
			}
			System.out.println();
			System.out.println();
			//int[]ris=preferite(m,1);
			//for(int i=0; i<ris.length; i++){
				//System.out.print(ris[i]+" ");}

		}

	
}
